<template>

  <div class="addUserInfo">
    <ViewTitle text="结算"/>


    <div class="box1">
      <div>
        <span>门诊号:</span>
        <el-input
          size="mini"
          disabled
          v-model="params.patient_no"
        >
        </el-input>
      </div>
      <div>
        <span>金额:</span>
        <el-input
          size="mini"

          v-model="params.amount"
        >
        </el-input>
      </div>

      <div>
        <span>结算方式:</span>
        <div>
          <el-select v-model="params.psn_setlway" placeholder="结算方式">
            <el-option
              v-for="(item, index) in thatF.jiesuanlist"
              :key="index"
              :label="item.name"
              :value="item.id"
            >{{ item.name }}
            </el-option
            >
          </el-select>
        </div>

      </div>
      <!-- <div v-if="thatF.thatF.activeName=='2'">
      <span>医疗类型:</span>
          <div>
             <el-select v-model="params.yibao_med_type" placeholder="请选择医疗类型" >
              <el-option
                v-for="(item,index) in yibao_med_type"
                :key="'index1'+index"
                :label="item.name"
                :value="item.value"

              >
              </el-option>
            </el-select>
      </div>

    </div> -->

      <div v-if="thatF.thatF.activeName=='2'">
        <span>医疗类别:</span>
        <div>
          <el-select size="mini" v-model="params.med_type" placeholder="医疗类别">
            <el-option
              v-for="(item,index) in dict_med_type"
              :key="'index1'+index"
              :label="item.name"
              :value="item.value"

            >
            </el-option>
          </el-select>
        </div>

      </div>
      <div>
        <span>个人账户使用标志 :</span>
        <div>
          <el-select v-model="params.acct_used_flag" placeholder="使用标志">
            <el-option label="否" value="0"></el-option>
            <el-option label="是" value="1">
            </el-option>
          </el-select>
        </div>

      </div>
      <div v-if="thatF.thatF.activeName=='2'">
        <span>处方单号:</span>
        <el-input
          size="mini"
          disabled
          v-model="params.order_number"
        >
        </el-input>
      </div>
      <div>
        <span>凭证编号:</span>
        <el-input
          size="mini"

          v-model="thatF.params.cert_no"
        >
        </el-input>
      </div>
      <div>
        <span>个人账户支出:</span>
        <el-input size="mini" placeholder="个人账户支出"
                  v-model="zhzcmoeny"
                  type="number"
                  @input="jisuangeren"
        >
        </el-input>
      </div>
      <div>
        <span style="width: 100px">就诊凭证类型:</span>
        <div>
          <el-radio-group v-model="cert_type">
            <el-radio label="01">电子凭证</el-radio>
            <el-radio label="02">身份证</el-radio>
            <el-radio label="03"> 社保卡</el-radio>
          </el-radio-group>
        </div>
      </div>

    </div>


    <div class="buts">
      <el-button class="butB_Add butB_Add2 " @click="duka">读卡</el-button>
      <el-button class="butB_Add butB_Add2 " @click="save(2)">预结算</el-button>
      <el-button class="butB_Add butB_Add1" @click="save(1)">结算</el-button>
      <el-button

        class="butB_Add"
        @click="handlel"
      >下载结算清单
      </el-button
      >
    </div>

    <ViewTitle text="预结算信息"/>
    <div class="box1">
      <div>
        <span>医疗费总额:</span>
        <el-input
          size="mini"
          disabled
          v-model="setlinfo.medfee_sumamt"
        >
        </el-input>
      </div>
      <div>
        <span>全自费金额:</span>
        <el-input
          size="mini"
          disabled
          v-model="setlinfo.fulamt_ownpay_amt"
        >
        </el-input>
      </div>
      <div>
        <span>超限价自费费用:</span>
        <el-input
          size="mini"
          disabled
          v-model="setlinfo.overlmt_selfpay"
        >
        </el-input>
      </div>
      <div>
        <span>先行自付金额:</span>
        <el-input
          size="mini"
          disabled
          v-model="setlinfo.preselfpay_amt"
        >
        </el-input>
      </div>
      <div>
        <span>符合政策范围金额:</span>
        <el-input
          size="mini"
          disabled
          v-model="setlinfo.inscp_scp_amt"
        >
        </el-input>
      </div>

      <div>
        <span>实际支付起付线:</span>
        <el-input
          size="mini"
          disabled
          v-model="setlinfo.act_pay_dedc"
        >
        </el-input>
      </div>

      <div>
        <span>基本医疗保险统筹基金支出:</span>
        <el-input
          size="mini"
          disabled
          v-model="setlinfo.hifp_pay"
        >
        </el-input>
      </div>

      <div>
        <span>基本医疗保险统筹基金支付比例:</span>
        <el-input
          size="mini"
          disabled
          v-model="setlinfo.pool_prop_selfpay"
        >
        </el-input>
      </div>

      <div>
        <span>公务员医疗补助资金支出:</span>
        <el-input
          size="mini"
          disabled
          v-model="setlinfo.cvlserv_pay"
        >
        </el-input>
      </div>

      <div>
        <span>企业补充医疗保险基金支出:</span>
        <el-input
          size="mini"
          disabled
          v-model="setlinfo.hifes_pay"
        >
        </el-input>
      </div>

      <div>
        <span>居民大病保险资金支出:</span>
        <el-input
          size="mini"
          disabled
          v-model="setlinfo.hifmi_pay"
        >
        </el-input>
      </div>

      <div>
        <span>职工大额医疗费用补助基金支出:</span>
        <el-input
          size="mini"
          disabled
          v-model="setlinfo.hifob_pay"
        >
        </el-input>
      </div>

      <div>
        <span>医疗救助基金支出:</span>
        <el-input
          size="mini"
          disabled
          v-model="setlinfo.maf_pay"
        >
        </el-input>
      </div>

      <div>
        <span>其他支出:</span>
        <el-input
          size="mini"
          disabled
          v-model="setlinfo.oth_pay"
        >
        </el-input>
      </div>

      <div>
        <span>基金支付总额:</span>
        <el-input
          size="mini"
          disabled
          v-model="setlinfo.fund_pay_sumamt"
        >
        </el-input>
      </div>

      <div>
        <span>个人负担总金额:</span>
        <el-input
          size="mini"
          disabled
          v-model="setlinfo.psn_part_amt"
        >
        </el-input>
      </div>

      <div>
        <span>个人账户支出:</span>
        <el-input
          size="mini"
          disabled
          v-model="setlinfo.acct_pay"
        >
        </el-input>
      </div>
      <div>
        <span>个人现金支出:</span>
        <el-input
          size="mini"
          disabled
          v-model="setlinfo.psn_cash_pay"
        >
        </el-input>
      </div>
      <div>
        <span>医院负担金额:</span>
        <el-input
          size="mini"
          disabled
          v-model="setlinfo.hosp_part_amt"
        >
        </el-input>
      </div>
      <div>
        <span>余额:</span>
        <el-input
          size="mini"
          disabled
          v-model="setlinfo.balc"
        >
        </el-input>
      </div>
      <div>
        <span>个人账户共济支付金额:</span>
        <el-input
          size="mini"
          disabled
          v-model="setlinfo.acct_mulaid_pay"
        >
        </el-input>
      </div>
      <div>
        <span>商保金额:</span>
        <el-input
          size="mini"
          disabled
          v-model="setlinfo.commercial_reimamt"
        >
        </el-input>
      </div>

      <div>
        <span>商保支付标志:</span>
        <el-input
          size="mini"
          disabled
          v-model="setlinfo.commercial_renflag"
        >
        </el-input>
      </div>
      <!-- <div>
       <span>医药机构结算ID:</span>
       <el-input
         size="mini"
          disabled
         v-model="setlinfo.medins_setl_id"
      >
       </el-input>
     </div>
      <div>
       <span>清算经办机构:</span>
       <el-input
         size="mini"
          disabled
         v-model="setlinfo.clr_optins"
      >
       </el-input>
     </div>
      <div>
       <span>清算方式:</span>
       <el-input
         size="mini"
          disabled
         v-model="setlinfo.clr_way"
      >
       </el-input>
     </div>
      <div>
       <span>清算类别:</span>
       <el-input
         size="mini"
          disabled
         v-model="setlinfo.clr_type"
      >
       </el-input>
     </div> -->
    </div>
  </div>
</template>
<script>
let t;

import ViewTitle from "@/forComponents/viewTitle/index.vue";
import {mapState, mapActions} from "vuex";
import {
  readcard_sbkjs,
} from "@/api/zhuyanre";

export default {
  props: ['thatF'],
  data() {
    return {
      params: {
        patient_no: '',
        amount: '',
        insutype: '',
        psn_setlway: '',
        med_type: '',
        acct_used_flag: '',
        order_number: '',
        mdtrt_cert_no: '',
        status: 1,
      },
      setlinfo: {},
      zhzcmoeny: '',
      Ident_code: '',
      cert_type: '02'
    };
  },
  mounted() {
    t = this;
    console.log(" t.thatF.thatF.yibao.selectItem", t.thatF.thatF.yibao.selectItem)
    t.params.patient_no = t.thatF.thatF.yibao.selectItem.patient_no;
    t.params.order_number = t.thatF.thatF.yibao.selectItem.number;
    if (t.thatF.thatF.activeName == '1') {
      t.params.amount = t.thatF.thatF.yibao.selectItem.amount;
    } else if (t.thatF.thatF.activeName == '2') {
      t.params.amount = t.thatF.thatF.yibao.selectItem.should_amount;
    }

  },

  methods: {
    duka() {
      console.log(this.cert_type)
      var d = {
        type: this.cert_type
      }
      if (this.cert_type == '02') {
        d.id_card = this.thatF.params.cert_no
        d.name = this.thatF.baseinfo.psn_name
      } else if (this.cert_type == '03') {
        d.xfmx = this.setlinfo.medfee_sumamt
        d.baa001 = this.thatF.params.selectData.insuplc_admdvs
        d.zhzc = this.zhzcmoeny
        d.tczf = this.setlinfo.hifp_pay
      } else if (this.cert_type == '01') {
        d.name = this.thatF.baseinfo.psn_name
      }
      readcard_sbkjs(d).then(res => {
        if (res.code == 200) {
          this.Ident_code = res.data
        } else {
          this.Ident_code = ''
        }


      })
    },
    commercial_renflag_info(type){
      let flag = '';
      switch (type){
        case '0':
          flag = '商保未缴费'
          break;
        case '1':
          flag = '商保正常报销'
          break;
        case '2':
          flag = '个人负担'
          break;
        case '3':
          flag = '商保计算服务调用异常'
          break;
        case '4':
          flag = '商保已支付'
          break;
        case '5':
          flag = '跨年结算商保线上报销'
          break;
        case 'null':
          flag = '不是住院类的结算和限定病种的门慢门特结算'
          break;
      }
      return flag
    },
    jisuangeren() {
      var num = parseFloat(this.setlinfo.balc)
      if (this.zhzcmoeny < 0) {
        this.zhzcmoeny = 0
      } else if (this.zhzcmoeny > num) {
        this.zhzcmoeny = num
      }
    },
    handlel() {
      this.thatF.thatF.handelDropdown('dwon1')

    },
    save(num) {
      //num 1是结算 2是预结算

      let url = num == 1 ? 'getclinic_feeSettlement' : 'getclinic_feePrepareSettlement'

      if (t.thatF.thatF.activeName == '1') {
        url = num == 1 ? 'getregisterSettlement' : 'getregisterPrepareSettlement';
      } else if (t.thatF.thatF.activeName == '2') {
        url = num == 1 ? 'getclinic_feeSettlement' : 'getclinic_feePrepareSettlement';
      }

      if (!t.params.psn_setlway) {
        return t.$message.error("请选择结算方式")
      }
      if (!t.params.acct_used_flag) {
        return t.$message.error("请选择个人使用标志")
      }
      let d = {
        patient_no: t.params.patient_no,
        amount: t.params.amount,
        insutype: t.thatF.params.insutype,
        psn_setlway: t.params.psn_setlway,
        card_sn: t.thatF.params.card_sn,
        acct_used_flag: t.params.acct_used_flag,
        insuplc_admdvs: t.thatF.params.selectData.insuplc_admdvs,
        // dise_name:t.thatF.params.dise_name,
        // dise_codg:t.thatF.params.dise_codg,
        // dise_type_code:t.thatF.params.dise_type_code
      }
      if (num == 1) {
        d.mdtrt_cert_no = t.thatF.params.cert_no;
        d.ip_code = t.Ident_code
        d.zhzc = t.zhzcmoeny
        d.mdtrt_cert_type = t.cert_type
      }
      if (t.thatF.thatF.activeName == '2') {
        d.med_type = t.params.med_type;
        d.order_number = t.params.order_number;

      }
      t['_API'][url](d).then(res => {
        if (res.code == 200) {
          if (num == 1) {
            this.$message({
              message: res.message,
              type: "success",
            });
            this.thatF.thatF.params.page = 1;
            this.thatF.thatF.getList()
            // this.thatF.params.jiesuanShow=false;
            //  this.thatF.thatF.yibao.show=false;
          } else {
            t.params.status = 2;
            t.setlinfo = res.data.output.setlinfo;
            t.setlinfo.commercial_renflag = this.commercial_renflag_info(t.setlinfo.commercial_renflag)
          }

        }
      })


    },


  },
  computed: {
    ...mapState({
      yibao_insutype: state => state.dictBai.yibao_insutype,
      yibao_med_type: state => state.dictBai.yibao_med_type,
      dict_med_type: state => state.dictBai.dict_med_type,
    }),
  },
  components: {
    ViewTitle,
    //  FormInfo
  },
};
</script>
<style lang='scss' scoped>
.addUserInfo {
  padding: 0 4%;

  .box1 {
    display: flex;
    flex-wrap: wrap;
    padding: 20px 0;

    > div {
      position: relative;
      width: 33%;
      display: flex;
      align-items: center;
      // justify-content: center;
      margin-bottom: 20px;

      > span {
        display: inline-block;
        width: 100px;
        margin-right: 10px;
      }

      /deep/ .el-input {
        width: 200px;
      }
    }
  }

  .box3 {
    margin: 20px 0;
  }

  .dukaBut {
    margin: 0px 0 20px;
  }
}

.buts {
  display: flex;
  align-items: center;
  justify-content: center;

  .butB_Add1 {


    width: 200px;

    bottom: 28px;
    right: 45px;
  }

  .butB_Add2 {


    width: 200px;

    bottom: 28px;
    right: 280px;
  }
}


</style>
